package com.whcoding.more.database.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @className DataSourceConfig
 * @Description 数据源配置
 * @Author whcoding
 * @Created Date 2018-12-8 9:46
 * @Modifier
 * @Modified Date
 * @Modified Remark
 * @Version 1.0
 */
@Configuration
public class DataSourceConfig {


    /**
     * oct 是对应的mysql 数据库
     * @return
     */
    @Primary
    @Bean(name = "octJpaDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.jpa.oct")
    public DataSource octJpaDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }

    /**
     * 对应的是mysql mybatis查询
     * @return
     */
    @Bean(name = "octMybatisDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.mybatis.oct")
    public DataSource octMybatisDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }

    /**
     * 对应的是 SqlServer 库
     * @return
     */
    @Bean(name = "middleMybatisDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.mybatis.middle")
    public DataSource middleMybatisDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }

}
